﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
//using System.Web.Security;
//using System.Web.UI;
//using System.Web.UI.HtmlControls;
//using System.Web.UI.WebControls;
//using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using MySql.Data.MySqlClient;

/// <summary>
///dbmanager 的摘要说明
/// </summary>


public class MydbmanagerSql
{
   
	public MydbmanagerSql()
	{
		//
		//TODO: 在此处添加构造函数逻辑
		//
	}
    //public static string strconn = CommitGlsr.Program.gs_sqlConn; //获取数据库
    public static DataTable ExecuteQuerySql(string strconn,string strSQL)
    {
        MySqlConnection conn = new MySqlConnection(strconn);
        try
        {
            MySqlDataAdapter adapter = new MySqlDataAdapter(strSQL, conn);
            DataSet ds = new DataSet();
            adapter.Fill(ds);
            return ds.Tables[0];
        }
     
        finally
        {
            if (conn.State == ConnectionState.Open)
                conn.Close();
        }
    }

  ////public static string strconn2 = CommitGlsr.Program.gs_sqlConn2; //获取数据库
  //public static DataTable ExecuteQuerySql2(string strconn,string strSQL)
  //{
  //    SqlConnection conn2 = new SqlConnection(strconn2);
  //    try
  //    {
  //        SqlDataAdapter adapter = new SqlDataAdapter(strSQL, conn2);
  //        DataSet ds = new DataSet();
  //        adapter.Fill(ds);
  //        return ds.Tables[0];
  //    }
  //
  //    finally
  //    {
  //        if (conn2.State == ConnectionState.Open)
  //            conn2.Close();
  //    }
  //}
    /// <summary>
    /// 执行对ACCESS数据库的插入、删除或修改操作
    /// </summary>
    /// <param name="strSQL">插入、删除或修改的SQL语句</param>
    /// <returns>返回插入、删除或修改的SQLyuju 所影响的行数</returns>
    public static int ExecuteNonQuerySql(string strconn,string strSQL)
    {

      //  string strconn = "Server=58.247.32.214,9480;Initial Catalog=iotIS;User ID=sa;Password=password";
        //string strconn = "Server=10.0.0.213;Initial Catalog=iotIS;User ID=sa;Password=password";
        MySqlConnection conn = new MySqlConnection(strconn);
        conn.Open();
        try
        {
            MySqlCommand cmd = new MySqlCommand(strSQL, conn);
            return (cmd.ExecuteNonQuery());
        }
        finally
        {
            if (conn.State == ConnectionState.Open)
                conn.Close();
        }
    }

 //  public static int ExecuteNonQuerySql2(string strSQL)
 //  {
 //
 //      //  string strconn = "Server=58.247.32.214,9480;Initial Catalog=iotIS;User ID=sa;Password=password";
 //      //string strconn = "Server=10.0.0.213;Initial Catalog=iotIS;User ID=sa;Password=password";
 //      SqlConnection conn2 = new SqlConnection(strconn2);
 //      conn2.Open();
 //      try
 //      {
 //          SqlCommand cmd = new SqlCommand(strSQL, conn2);
 //          return (cmd.ExecuteNonQuery());
 //      }
 //      finally
 //      {
 //          if (conn2.State == ConnectionState.Open)
 //              conn2.Close();
 //      }
 //  }
    public static object ExecuteScalarSql(string strconn,string strSQL)
    {

        //string strconn = "Server=58.247.32.214,9480;Initial Catalog=iotIS;User ID=sa;Password=password";
        //string strconn = "Server=10.0.0.213;Initial Catalog=iotIS;User ID=sa;Password=password";
        MySqlConnection conn = new MySqlConnection(strconn);
        conn.Open();
        try
        {
            MySqlCommand cmd = new MySqlCommand();
            cmd = conn.CreateCommand();
            cmd.CommandType = CommandType.Text;
            cmd.CommandText = strSQL;
            return cmd.ExecuteScalar();
        }
        finally
        {
            if (conn.State == ConnectionState.Open)
                conn.Close();
        }
    }
}
